﻿// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
//
// 本项目主要遵循 MIT 许可证和 Apache 许可证（版本 2.0）进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
//
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动！任何基于本项目二次开发而产生的一切法律纠纷和责任，我们不承担任何责任！

using Admin.NET.Application.Entity;
using Admin.NET.Core.Service.BarCode.Dto;

namespace Admin.NET.Core.Service.BarCode;


/// <summary>
/// 出入库 jk001
/// </summary>
[ApiDescriptionSettings(groups: ApplicationConst.GroupName, Order = 370)]
public class SysBarcodService : IDynamicApiController
{
    /// <summary>
    /// 出入库dto
    /// </summary>
    private readonly SqlSugarRepository<Core.Service.BarCode.Dto.WarehouseControle> _inventroy;
    /// <summary>
    /// 出入库实体
    /// </summary>
    private readonly SqlSugarRepository<OrderInfoEntity> _boundOrder;


    public SysBarcodService(SqlSugarRepository<Core.Service.BarCode.Dto.WarehouseControle> warehouseBarcodeRep, SqlSugarRepository<OrderInfoEntity> order)
    {
        _inventroy = warehouseBarcodeRep;

        _boundOrder = order;
    }

    /// <summary>
    /// 入库订单下发 🔖
    /// </summary>
    /// <param name="order"></param>
    /// <returns></returns>
    public async Task<object> IInboundOrderService(WarehouseControle order)
    {
        //入库逻辑
        var OrderDetailList = order.Orders.Select(u => new OrderDetail
        {
            Arecode = u.Arecode,
            OrderLine = u.OrderLine,
            OrderNumber = u.OrderNumber,
            OrderType = u.OrderType,
            PartList = u.PartList

        }).ToList();
        await _inventroy.InsertAsync(order);
        //redis里获取 agv 提升机状态  查询库存库位， 


        return new { Success = true, Message = "入库成功", Date = 1 };

    }

    /// <summary>
    /// 出库订单下发 🔖
    /// </summary>
    /// <param name="order"></param>
    /// <returns></returns>
    public async Task<object> IOutboundOrderService(WarehouseControle order)
    {
        //出库逻辑 dto转entity
        var OrderDetailList = order.Orders.Select(u => new OrderDetail
        {
            Arecode = u.Arecode,
            OrderLine = u.OrderLine,
            OrderNumber = u.OrderNumber,
            OrderType = u.OrderType,
            PartList = u.PartList

        }).ToList();
        await _inventroy.InsertAsync(order);
        return new { Success = true, Message = "出库成功", Code = 1 };

    }

    /// <summary>
    ///库存交接🔖
    /// </summary>
    /// <param name="barcodeslist"></param>
    /// <returns></returns>
    [DisplayName("库存交接")]
    public async Task<List<BarcodeResponse>> OutboundDelivery(List<BarcodeResponse> barcodeslist)
    {
        return await Task.FromResult(barcodeslist); //await barcodeslist.Where(BarcodeResponse => BarcodeResponse.).ToList();


    }




    //// 条码信息下发接口
    //public interface IBarcodeInfoService
    //{
    //    object SendBarcodeInfo(string barcodeInfo);
    //}

    //// 实现 IInventoryHandoverService 接口
    //public void HandoverInventory(InventoryHandover handoverInfo)
    //{
    //    // 实现库存交接逻辑
    //    // 这里可以添加具体的业务逻辑

    //}

    //// 库存交接接口
    //public interface IInventoryHandoverService
    //{
    //    void HandoverInventory(InventoryHandover handoverInfo);
    //}
}




